<?php
namespace Api\Controller;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

use Gy_Library\CusSession;
use Gy_Library\RestController;
use phpDocumentor\Reflection\Types\Null_;

/**
 * Description of LoginController
 *
 * @author hardy
 */
class PracticeController extends RestController {
    use DataMachiningController;

    /*说明开始
    method:get

    version:
    parameter:
       选填 page 页码数
       选填 id 练习的id 如果这个id值不填则返回的是练习列表，如果填了，则返回该ID的练习数据（一条）
        return:
        data.return  口译练习列表
    description: 口译练习列表
    说明结束*/
    public function gets(){
        $user_id = $this->getSessionId();
        $id = I('get.id', 0);
        $model = D('Practice');
        $map['student_id'] = $user_id;
        if(empty($id)){
            $this->getPageData($model, $map, 'id desc','getListForApiPage');
        }else{
            $map['id'] = $id;
            $data = $model->getPracticeOneApi($map);
            $this->setSuccessMessageOneData($data);
        }
    }
    /*说明开始
    method:post
    version:
    parameter:
        必选 字段 介绍
            title       标题
            type_id     练习类型id
            content     内容
            test_id     素材id
            file_id     练习音频文件id
            self_feedback    自我反馈
        return:
        status 状态码 1 成功 0 失败
        info  提示信息
    description: 上传口译练习
    说明结束*/
    public function create(){
        $user_id = $this->getSessionId();
        $data = I('post.');
        $duration = D('FilePic')->getDurationJudgeAudio($data['file_id']);
        if($duration === null){
            $this->setFailMessage('请上传音频文件');
        }
        $data['student_id'] = $user_id;
        $data['duration'] = $duration;
        $model = D('Practice');
        $this->createInsertDB($model, $data);
        $this->setSuccessMessageOneData();
    }
    /*说明开始
    method:delete
    version:
    parameter:
        必填 id 口译练习的id
    return:
    description: 删除口译练习信息
    说明结束*/
    public function delete(){
        $user_id = $this->getSessionId();
        $map['student_id'] = $user_id;
        $model = D('Practice');
        $this->deleteModelData($model, $map);
    }
}
